var Step = require('step');

var app = exports = module.exports = {};

app.networks = function networks(callback) {
	callback(null, ['facebook', 'twitter','linkedin']);
}

app.facebook = function facebook(callback) {
	setTimeout(function() {
	  	  console.log("pulling facebook data.");
	  	  callback(null, {data: 'facebook data'});
	  	}, 5000);
}

app.twitter = function twitter(callback) {
	setTimeout(function() {
	  	  console.log("pulling twitter data.");
	  	  callback(null, {data: 'twitter data'});
	  	}, 3000);
}

app.linkedin = function linkedin(callback) {
	setTimeout(function() {
	  	  console.log("pulling linkedin data.");
	  	  callback(null, {data: 'linkedin data'});
	  	}, 2000);
}

app.getData = function(callback) {
	Step(
		function getNetworks() {
			app.networks(this);    
		},
		function getData(err, networks) {
			if (err) throw err;

			var group = this.group();

			networks.forEach(function(network)
			{
				app[network](group());
			});
		},
		function returnData(err, data) {
			if (err) throw err;

			callback(data);
		}
	);
}